package org.mybatis.demo.plugins;

/**
 * @author yangjian
 */
public class PageHelper {

  private static ThreadLocal<Page> localPage = new ThreadLocal<>();

  public static void startPage(int pageSize)
  {
    Page page = new Page(1, pageSize);
    localPage.set(page);
  }

  public static void startPage(int pageNo, int pageSize)
  {
    if (pageNo <= 0) {
      pageNo = 1;
    }
    Page page = new Page(pageNo, pageSize);
    // 将分页数据保存到 ThreadLocal 中
    localPage.set(page);
  }

  // 获取分页数据
  public static Page getPage()
  {
    return localPage.get();
  }

  // 清除分页信息
  public static void removePage()
  {
    localPage.remove();
  }
}
